import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_module/system/colors_config.dart';

class MyDialog extends StatelessWidget {
  final ValueChanged callback;
  final Key? key;
  final String title;
  final String content;
  final bool bHisCancel;

  const MyDialog({
    required this.callback,
    this.key,
    this.bHisCancel: true,
    required this.title,
    required this.content,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.transparent,
        body: Center(
          child: Card(
            elevation: 2,
            margin: const EdgeInsets.only(left: 20, right: 20),
            color: MyColors.secondBlackFillColor,
            shadowColor: MyColors.textWhiteColor,
            child: Padding(
              padding:
              const EdgeInsets.only(top: 20, bottom: 30, left: 15, right: 15),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Image.asset('assets/icon_dangerous.png',width: 65,height: 60,),
                  const SizedBox(
                    height: 10,
                  ),
                  Text(
                    title,
                    style:
                    const TextStyle(color: MyColors.textBlueColor, fontSize: 20),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Text(
                    content,
                    style:
                    const TextStyle(color: MyColors.textWhiteColor, fontSize: 15),
                  ),
                  const SizedBox(
                    height: 30,
                  ),
                  _getButtons(context),
                ],
              ),
            ),
          ),
        ));
  }

  Widget _getButtons(BuildContext context) {
    if (!bHisCancel) {
      return CupertinoButton(
        padding: EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 5),
        child: Container(
          width: 300,
          child: const Text(
            '确定',
            textAlign: TextAlign.center,
            style: TextStyle(
              color: MyColors.mainBlackColor,
              fontSize: 18,
            ),
            maxLines: 1,
          ),
        ),
        onPressed: () {
          callback(true);
          Navigator.maybePop(context);
        },
        color: MyColors.textBlueColor,
      );
    } else {
      return Row(
        children: [
          Flexible(
            child: Padding(
              padding: const EdgeInsets.only(right: 10),
              child: CupertinoButton(
                padding:
                const EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 5),
                child: Container(
                  width: double.infinity,
                  child: const Text(
                    '取消',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 18,
                    ),
                    maxLines: 1,
                  ),
                ),
                onPressed: () {
                  Navigator.maybePop(context);
                },
                color: MyColors.mainGrayColor,
              ),
            ),
          ),
          Flexible(
            child: Padding(
              padding: const EdgeInsets.only(left: 10),
              child: CupertinoButton(
                padding:
                const EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 5),
                child: Container(
                  width: double.infinity,
                  child: const Text(
                    '确定',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: MyColors.mainBlackColor,
                      fontSize: 18,
                    ),
                    maxLines: 1,
                  ),
                ),
                onPressed: () {
                  callback(true);
                  Navigator.maybePop(context);
                },
                color: MyColors.textBlueColor,
              ),
            ),
          ),
        ],
      );
    }
  }
}
